package sdk.webview.fmc.com.fmcsdk.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import sdk.webview.fmc.com.fmcsdk.R;
import sdk.webview.fmc.com.fmcsdk.util.NetworkUtils;


public class CreamOrVideoRecordDialog extends Dialog implements View.OnClickListener {
    private ClickListenerInterface clickListenerInterface;
    public CreamOrVideoRecordDialog(@NonNull Context context) {
        super(context,R.style.Dialog);
    }

    public CreamOrVideoRecordDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
    }

    protected CreamOrVideoRecordDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_select_cream_or_video);
        //设置dialog窗口属性
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        //dialogWindow.setGravity(Gravity.LEFT | Gravity.TOP);
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.gravity = Gravity.BOTTOM;
        dialogWindow.setAttributes(lp);
        RelativeLayout rl_take_photo = (RelativeLayout) findViewById(R.id.rl_take_photo);
        rl_take_photo.setOnClickListener(this);
        RelativeLayout rl_video_recording = (RelativeLayout) findViewById(R.id.rl_video_recording);
        rl_video_recording.setOnClickListener(this);
        if(!NetworkUtils.isAvailable(getContext())){
            rl_video_recording.setVisibility(View.GONE);
        }
        LinearLayout ll_cancel = (LinearLayout) findViewById(R.id.ll_cancel);
        ll_cancel.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.rl_take_photo){
            clickListenerInterface.takePhoto();
        }else if (v.getId()==R.id.rl_video_recording){
            clickListenerInterface.recordVideo();
        }else if (v.getId()==R.id.ll_cancel){
            dismiss();
        }

    }
    public void setClickListener(ClickListenerInterface clickListenerInterface) {
        this.clickListenerInterface = clickListenerInterface;
    }
    public interface ClickListenerInterface {

         void takePhoto();

         void recordVideo();
    }
}
